#include <iostream>
#include<algorithm>
#include<cstdio>
#include<iterator>
using namespace std;


int N;
int yN=0;
int sum=0;
int scanlength=0;
int scanseg=0;
int scanpos=-10000;
int newscanlength;
int newscanseg;


int index[10001];  //record all y values

struct st_node{
	int lowi, upi;// segment 's upper and lower points
	int ysum; //length
	int lf,uf;  //flag to indicate whether ending points are reached
	int cs;  // number of segments
	int counter; //volatible 
	int left, right; //0 means null
	//struct st_node *left, *right;
}nodes[10001];

struct vert_line
{
	int x;
	int ylow,yup;
	int flag; // left=1 right=-1
	bool operator<(const vert_line &vl)const
	{
		return x<vl.x;
	}
}lines[10001];

int getIndex(int key)
{
	for(int i=0;i<yN;++i)
		if(key==index[i])
			return i;
}
void make_st_tree_r(int s, int t, int i)
{
	nodes[i].lowi=s;
	nodes[i].upi=t;
	nodes[i].counter=0;
	nodes[i].cs=0;	
	nodes[i].lf=nodes[i].uf=0;
	nodes[i].ysum=0;
	if(t-s>1){
		nodes[i].left=2*i;
		nodes[i].right=2*i+1;
		int mid=(t+s)>>1;
		make_st_tree_r(s,mid,2*i);
		make_st_tree_r(mid,t,2*i+1);
	}
	else{
		nodes[i].left=0;
		nodes[i].right=0;
	}
}

void st_insert(int lowi,int upi,int flag,int i)
{
	if(lowi==nodes[i].lowi && upi==nodes[i].upi){// insert into current node(i)
		nodes[i].counter+=flag;
		if(flag>0 && nodes[i].counter==1){
			nodes[i].lf=nodes[i].uf=nodes[i].cs=1;
			nodes[i].ysum=index[upi]-index[lowi];
		}
	}
	else if(upi<=nodes[nodes[i].left].upi){//insert into the left without split
		st_insert(lowi,upi,flag,nodes[i].left);
	}
	else if(lowi>=nodes[nodes[i].right].lowi){//insert into the right without split
		st_insert(lowi,upi,flag,nodes[i].right);
	}
	else{ // split and insert into the both children
		st_insert(lowi,nodes[nodes[i].left].upi,flag,nodes[i].left);
		st_insert(nodes[nodes[i].right].lowi,upi,flag,nodes[i].right);
	}
	// tail procedure before return to the upper call
	if(nodes[i].counter==0){
		/*execute shift nodes[i]*/
		if(nodes[i].left==0){// leaf node, no child
			nodes[i].lf=nodes[i].uf=nodes[i].cs=0;
			nodes[i].ysum=0;
		}
		else{
			nodes[i].lf=nodes[nodes[i].left].lf;
			nodes[i].uf=nodes[nodes[i].right].uf;
			nodes[i].ysum=nodes[nodes[i].left].ysum+nodes[nodes[i].right].ysum;
			nodes[i].cs=nodes[nodes[i].left].cs+nodes[nodes[i].right].cs;
			if(nodes[nodes[i].left].uf==1 && nodes[nodes[i].left].uf==nodes[nodes[i].right].lf)
				nodes[i].cs-=1;
		}
	}
	//else(flag<0 && nodes[i].counter>0 ) { not bother to do}
}

int main()
{
	cin>>N; //N<5000
	int x1,y1,x2,y2;
	for(int i=0;i<N;++i){
		scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
		if(x1>x2)
			swap(x1,x2);
		if(y1>y2)
			swap(y1,y2);
		lines[2*i].x=x1; 
		lines[2*i+1].x=x2;
		lines[2*i].ylow=lines[2*i+1].ylow=y1;
		lines[2*i].yup=lines[2*i+1].yup=y2;
		lines[2*i].flag=1;
		lines[2*i+1].flag=-1;
		index[2*i]=y1;
		index[2*i+1]=y2;
	}
	sort(lines,lines+2*N);
	sort(index,index+2*N);
	index[yN++]=index[0];
	for(int i=1; i<2*N; ++i){// make unique index
		if(index[i] != index[i-1])
			index[yN++]=index[i];
	}

	make_st_tree_r(0,yN-1,1);
	int cur_x=lines[0].x;
	for(int i=0; i<2*N; ){
		//while(i<2*N && cur_x== lines[i].x){
		//st_insert(getIndex(lines[i].ylow),getIndex(lines[i].yup),lines[i].flag,1);
		//	++i;
		//}
		
		st_insert(getIndex(lines[i].ylow),getIndex(lines[i].yup),lines[i].flag,1);
		++i;
		newscanlength=nodes[1].ysum;
		newscanseg=nodes[1].cs;
		sum+=2*scanseg*(cur_x-scanpos);
		sum+=abs(newscanlength-scanlength);
		scanseg=newscanseg;
		scanlength=newscanlength;
		scanpos=cur_x;

		if(i<2*N)
			cur_x=lines[i].x;
	}
	printf("%d\n",sum);
	return 0;
}
